package com.ruoyi.warehouse.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.entity.OrderRequest;
import com.ruoyi.warehouse.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：tianshuai
 * @description：order
 * @date ：2025/3/19 17:28
 */
@RestController
@RequestMapping("/orders")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    /**
     * 获取订单列表
     *
     * @param orderRequest 订单请求对象，包含查询条件
     * @return 订单列表信息
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('order:list')")
    public long list(OrderRequest orderRequest) {
//        startPage();
//        List<OrderRequest> list = orderService.getOrderList(orderRequest);
//        return getDataTable(list);
        return 1;
    }

    /**
     * 根据订单ID获取订单信息
     *
     * @param orderId 订单ID
     * @return 订单信息
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable Long orderId) {
        return success(orderService.selectOrderById(orderId));
    }

    /**
     * 添加订单信息
     *
     * @param order 订单请求对象，包含要添加的订单信息
     * @return 添加结果
     */
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody OrderRequest order) {
        order.setCreateBy(getUsername());
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 更新订单信息
     *
     * @param order 订单请求对象，包含要更新的订单信息
     * @return 更新结果
     */
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/{orderId}")
    public AjaxResult edit(@PathVariable Long orderId, @Validated @RequestBody OrderRequest order) {
//        order.setOrderId(orderId);
        order.setUpdateBy(getUsername());
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 根据订单ID数组删除订单信息
     *
     * @param orderIds 订单ID数组
     * @return 删除结果
     */
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(orderService.deleteOrderByIds(orderIds));
    }

}